from . import ElementHelper as helper
from . import DotHelper as dot
def toDotString(the_list,cur_node_key=None):
    '''
    :param the_list:
    :param cur_node_key: 当前节点key
    :return: 顺序表转Dot脚本
    '''
    template ='''
    graph G {
    fontname="Helvetica,Arial,sans-serif"
    
	node [shape=box];
    %s
    }'''

    nodes=''
    for index,item in enumerate(the_list):
        if item:
            if cur_node_key == helper.getKey(item) or cur_node_key == index:
                nodes +=f'\nn{index} [label="{index}:{helper.getLabel(item)}" fontcolor="red"  color="red"];'
            else:
                nodes += f'\nn{index} [label="{index}:{helper.getLabel(item)}"];'
        else:
            nodes += f'\nn{index} [label="{index}:"];'
    return template%nodes